package com.csl.testjetpack.data.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.csl.testjetpack.data.bean.RemoteAndButton
import com.csl.testjetpack.data.bean.RemoteButtonInfo
import com.csl.testjetpack.data.bean.RemoteInfo
import org.jetbrains.annotations.NotNull

@Dao
interface RemoteDao {
    //查询分多次执行, 添加事务标签确保原子性
    @get:Query("SELECT * FROM RemoteInfo")
    @get:Transaction
    val allRemote: LiveData<List<RemoteInfo>?>

    @Insert
    fun insert(vararg remote: RemoteInfo): LongArray

    @Update
    fun update(vararg remote: RemoteInfo)

    @Delete()
    fun delete(vararg remote: RemoteInfo)

//    @Delete(entity = RemoteInfo::class)
//    fun deleteRemote(vararg remoteid: Long)

    @Transaction //查询分多次执行, 添加事务标签确保原子性
    @Query("SELECT * FROM RemoteBtnInfo WHERE remote_id = :remoteid")
    fun getRemoteBtn(remoteid: Long): LiveData<List<RemoteButtonInfo>>

    @Transaction //查询分多次执行, 添加事务标签确保原子性
    @Query("SELECT * FROM RemoteInfo")
    fun getRemoteInfo(): List<RemoteAndButton>

    @Insert
    fun insert(vararg btn: RemoteButtonInfo)

    @Update
    fun update(vararg remote: RemoteButtonInfo)

    @Delete
    fun delete(vararg remote: RemoteButtonInfo)
}